/**
 * Created by charsen on 15/11/9.
 */
var DIRECTIVES = angular.module("DIRECTIVES", ["SERVICES"]);
// 导航
DIRECTIVES.directive("nav", ["$rootScope", "tools", function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            scope.curr = attrs.curr;
            scope.tabs = [
                {
                    value: 'index',
                    hash: '#/index',
                    name: ['系统', '概况']
                },
                {
                    value: 'monitor',
                    hash: '#/monitor',
                    name: ['效果', '监控']
                },
                {
                    value: 'compare',
                    hash: '#/compare',
                    name: ['数据', '对比']
                },
                {
                    value: 'mapdata',
                    hash: '#/mapdata',
                    name: ['全景', '数据']
                }
            ];
        },
        templateUrl: '/dataview/html/widgets/nav.html'
    }
}]);
// 全屏
DIRECTIVES.directive('fullScreen', ['$rootScope', 'tools', function ($rootScope, tools) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            var chart_ele = null;
            var $full_screen_container = $('#full-screen-container');
            $rootScope.$on('fullscreen', function (e, option) {
                chart_ele = $("<div class = 'full-screen-box w h'></div>");
                $full_screen_container.append(chart_ele);
                var chart = echarts.init(chart_ele[0], theme);
                chart.setOption(option);
                $full_screen_container.animate({
                    top: '0'
                }, 500);
            });
            document.body.onkeydown = function (e) {
                if (e.keyCode == 27) {
                    $full_screen_container.animate({
                        top: '-100%'
                    }, 500, function () {
                        $full_screen_container.html('');
                    });
                }
            }
            scope.quit = function () {
                $full_screen_container.animate({
                    top: '-100%'
                }, 500, function () {
                    chart_ele.css('display', 'none');
                });
            }
        },
        template: '<div id = "full-screen-container"><b class = "full-screen-quit" ng-click = "quit()">退出全屏</b></div>'
    }
}]);
DIRECTIVES.directive('topSalers', ['$rootScope', 'tools', "$interval", function ($rootScope, tools, $interval) {
    return {
        restrict: 'AE',
        scope: {},
        replace: true,
        link: function (scope, element, attrs) {
            scope.topSalers = [];

            var scrollSalers = function () {
                var y = 0;
                $interval(function () {
                    $(element).find('table').css({
                        marginTop: -1 * y++
                    });
                    if (y > $(element).find('table').height() - $(element).height()) {
                        $(element).find('table').css({
                            marginTop: 0
                        });
                        y = 0;
                    }
                }, 50);
            }

            tools.get({
                url: '/Intelligence-Business-Management/getDatasByModuleId.htm',
                data: {
                    uuid: '69341649-c33d-4fd3-b6d1-7d264df7c8b0',
                    moduleId: '1716110043335',
                    moduleType: 'data',
                    sortType: 'desc',
                    sortField: 'doub4',
                },
                succ: function (resp) {
                    if (resp.success) {
                        for (var i = 1; i < 30; i++) {
                            scope.topSalers.push({
                                name: resp.value.datas[i][0],
                                saleMoney: resp.value.datas[i][1],
                                saleMount: resp.value.datas[i][2],
                                perPrice: resp.value.datas[i][3],
                                town: resp.value.datas[i][4],
                                village: resp.value.datas[i][5]
                            });
                        }
                        scrollSalers();
                    }
                }
            });
        },
        templateUrl: "/dataview/html/widgets/topSalers.html"
    }
}]);